/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import ControllerInterface.IControllerCrawler;
import ControllerInterface.IControllerStatsMap;
import ViewInterface.AbstractViewMapFactory;
import ViewInterface.IViewStats;
import java.io.File;

/**
 *
 * @author Fabian
 */
public class ControllerStatsMap implements IControllerStatsMap {
    
    private String dataSource;
    private IViewStats vistaStats;
    private IControllerCrawler myController;
    private long tamanoActual = 0;
    private long tamanoRelativo = 0;

    
    /**
     * 
     */
    @Override
    public void initStats() {
        vistaStats = AbstractViewMapFactory.getAbstractViewMapFactory().getVistaStats();
        vistaStats.setController(this);
        vistaStats.initStats();
        
    }

    /**
     * 
     * @param controlador
     */
    @Override
    public void setController(IControllerCrawler controlador) {
        myController = controlador;
    }

    /**
     * 
     * @param xmlFile
     */
    @Override
    public void setdataSource(String xmlFile) {
        dataSource = xmlFile;
    }

    /**
     * 
     */
    @Override
    public void stopExtraction() {
        myController.stopExtraction();
    }

    /**
     * 
     */
    @Override
    public void resumeExtraction() {
        myController.resumeExtraction();
    }
    
    /**
     * 
     * @return
     */
    public long[] getSizeFile(){
        File fichero = new File("DataSource/" + dataSource);
        long[] tamano = new long[2];
        long aux = fichero.length();
        if (tamanoActual > aux) {
            tamano[0] = tamanoActual;
            tamano[1] = tamanoRelativo;
        } else {
            tamanoRelativo = aux - tamanoActual;
            tamanoActual = aux;
            tamano[0] = tamanoActual;
            tamano[1] = tamanoRelativo;
        }
        return tamano;
    }
    
}
